package com.neusoft.aclome.cmp.cloud.server.jcce.wrapper;

import com.neusoft.aclome.cmp.cloud.server.jcce.dto.response.JcceJobDTO;
import com.neusoft.aclome.cmp.cloud.server.jcce.entity.JcceJobEntity;
import com.neusoft.aclome.cmp.common.model.wrapper.BaseDTOEntityWrapper;
import com.neusoft.aclome.cmp.common.utils.FieldUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * describe :
 *
 * @author hao.dd
 * @date 2023/8/15
 */
@Service
public class JcceJobWrapper implements BaseDTOEntityWrapper<JcceJobDTO, JcceJobEntity> {
    @Override
    public JcceJobDTO toDTOFromEntity(JcceJobEntity entity, JcceJobDTO dto) {
        if (null == dto) {
            dto = new JcceJobDTO();
        }
        FieldUtils.convertModel(entity, dto);
//        dto.setInstanceId(entity.getId().toString());
//        PubRdsMysqlStateEnums state = PubRdsMysqlStateEnums.valueOf(entity.getState());
//        dto.setState(state);
//        dto.setStateName(state.getLocalName());
//        String instanceChargeType = entity.getInstanceChargeType();
//        if (StringUtils.isNotBlank(instanceChargeType)) {
//            dto.setInstanceChargeType(InstanceChargeType.valueOf(instanceChargeType));
//            dto.setInstanceChargeTypeName(InstanceChargeType.valueOf(instanceChargeType).getName());
//        }
//
//        String internetChargeType = entity.getInternetChargeType();
//        if(StringUtils.isNotBlank(internetChargeType)){
//            dto.setInternetChargeType(InternetChargeType.valueOf(internetChargeType));
//            dto.setInternetChargeTypeName(InternetChargeType.valueOf(internetChargeType).getName());
//        }

        return dto;
    }

    @Override
    public JcceJobEntity toEntityFromDTO(JcceJobDTO dto, JcceJobEntity entity) {
        if (null == entity) {
            entity = new JcceJobEntity();
        }
        FieldUtils.convertModel(dto, entity);
        if (dto.getArch() != null) {
            entity.setArch(dto.getArch().name());
        }
//        if (dto.getState() != null) {
//            entity.setState(dto.getState().name());
//        }
//        if (dto.getInstanceType() != null) {
//            entity.setInstanceType(dto.getInstanceType().name());
//        }
//        entity.setPlatformResourceId(dto.getInstanceId());
        return entity;
    }

    @Override
    public List<JcceJobDTO> toDTOListFromEntity(List<JcceJobEntity> entities) {
        List<JcceJobDTO> dtos = new ArrayList<>();
        if (!CollectionUtils.isEmpty(entities)) {
            entities.forEach(entity -> dtos.add(toDTOFromEntity(entity, null)));
        }
        return dtos;
    }

    @Override
    public List<JcceJobEntity> toEntityListFromDTO(List<JcceJobDTO> dtos) {
        List<JcceJobEntity> entities = new ArrayList<>();
        if (!CollectionUtils.isEmpty(dtos)) {
            dtos.forEach(dto -> entities.add(toEntityFromDTO(dto, null)));
        }
        return entities;
    }
}
